/**
 * 初始化 daterangepicker 的封装
 *
 * 约定：dateId为日期框的ID
 *
 * @author wjf
 */
(function() {
	var DateRangePicker = function(divDateId, searchDateId) {
		this.divDateId = divDateId; //日期框ID
		this.searchDateId = searchDateId; //日期搜索框ID
		this.minDate = '2015-01-01'; //最小时间
		this.maxDate = moment(); //最大时间 
		this.dateLimit = {
			days: 365 * 5
		}; //起止时间的最大间隔
		this.showDropdowns = true;
		this.showWeekNumbers = false; //是否显示第几周
		this.timePicker = false; //是否显示小时和分钟
		this.timePickerIncrement = 60; //时间的增量，单位为分钟
		this.timePicker12Hour = false; //是否使用12小时制来显示时间
		this.ranges = {
			//'最近1小时': [moment().subtract('hours',1), moment()],
			'今日': [moment().startOf('day'), moment()],
			'昨日': [moment().subtract('days', 1).startOf('day'), moment().subtract('days', 1).endOf('day')],
			'最近7日': [moment().subtract('days', 6), moment()],
			'最近30日': [moment().subtract('days', 29), moment()]
		};
		this.opens = 'right'; //日期选择框的弹出位置
		this.buttonClasses = ['btn btn-default'];
		this.applyClass = 'btn-small btn-primary blue';
		this.cancelClass = 'btn-small';
		this.format = 'YYYY-MM-DD'; //控件中from和to 显示的日期格式
		this.separator = ' 至 ';
	};

	DateRangePicker.prototype = {
		/**
		 * 初始化daterangepicker
		 */
		init: function() {
				var searchDateId = this.searchDateId;
				$('#' + this.divDateId).daterangepicker({
					minDate: this.minDate, //最小时间
					maxDate: this.maxDate, //最大时间 
					dateLimit: this.dateLimit, //起止时间的最大间隔
					showDropdowns: this.showDropdowns,
					showWeekNumbers: this.showWeekNumbers, //是否显示第几周
					timePicker: this.timePicker, //是否显示小时和分钟
					timePickerIncrement: this.timePickerIncrement, //时间的增量，单位为分钟
					timePicker12Hour: this.timePicker12Hour, //是否使用12小时制来显示时间
					ranges: this.ranges,
					opens: this.opens, //日期选择框的弹出位置
					buttonClasses: this.buttonClasses,
					applyClass: this.applyClass,
					cancelClass: this.cancelClass,
					format: this.format, //控件中from和to 显示的日期格式
					separator: this.separator,
					locale: {
						applyLabel: '确定',
						cancelLabel: '取消',
						fromLabel: '起始时间',
						toLabel: '结束时间',
						customRangeLabel: '自定义',
						daysOfWeek: ['日', '一', '二', '三', '四', '五', '六'],
						monthNames: ['一月', '二月', '三月', '四月', '五月', '六月',
							'七月', '八月', '九月', '十月', '十一月', '十二月'
						],
						firstDay: 1
					} //汉化日期控件
				}, function(start, end, label) {
					//格式化日期显示框
					$('#' + searchDateId).val(start.format('YYYY-MM-DD') + ' 至 ' + end.format('YYYY-MM-DD'));
				});
			return this;

		},
	};
	window.DateRangePicker = DateRangePicker;
}());